var clickStatus=true;
$(document).ready(function(){
	$(".ui_checkb .ico").click(function(){
		if ($(this).hasClass("ico_hov")) {
			$(this).removeClass("ico_hov");
			$(this).parent().find("input[type='checkbox']").attr("checked",false);
		} else {
			$(this).addClass("ico_hov");
			$(this).parent().find("input[type='checkbox']").attr("checked",true);
		}
	});

	$(".jia_obj").click(function(){
        num_val = parseInt($(this).parent().children(".num_txt_obj").val());
        total = $(this).parent().children(".num_txt_obj").attr("total");
        if (num_val >= total) {
            num_val = total;
            layer.msg("已到达最大库存！");
        } else {
            num_val = num_val + 1;
        }
        $(this).parent().children(".num_txt_obj").val(num_val);
    });
        
    $(".jian_obj").click(function(){
        num_val = parseInt($(this).parent().children(".num_txt_obj").val());
        total = $(this).parent().children(".num_txt_obj").attr("total");
        if (num_val <= 1) {
            num_val = 1;
        } else {
            num_val = num_val - 1;
        }
        $(this).parent().children(".num_txt_obj").val(num_val);
    });
    $("#save-button").click(function(){
    	var details=$(".detail-checkbox:checked");
    	if(details.length==0){
    		layer.msg( '请选择售后商品！');
    		return false;
    	}
    	var remark = $("#remark").val();
    	if(remark.length==0){
    		layer.msg( '请输入退货原因！');
			return false;
    	}
    	var orderDetails = new Array();
		$("div .ui_sqsh_c1 li").each(function(i,item){
			var goodsCheck = $(item).find(".detail-checkbox").attr("checked");
			if(goodsCheck == "checked"){
				var detailId = $(item).find(".detail-checkbox").val();
				var quantity = $(item).find(".refund-quantity").val();
				var orderDetail = {
						"id":detailId,
						"quantity":quantity,
				}
				orderDetails.push(orderDetail);
			}
			
		});
		var isSend=0;//未发货
		refundExpress=null;
		if($("#is_send_true").prop("checked")){
			isSend=1;//已发货
			if($("#is_ship_true").prop("checked")){
				var shipNo = $("#txtShipNo").val();
				if($.trim(shipNo).length == 0){
					layer.msg($("#txtShipNo").prop("placeholder"))
					return false;
				}
				var shipCompanyName = $("#txtShipCompanyName").val();
				if($.trim(shipCompanyName).length == 0){
					layer.msg($("#txtShipCompanyName").prop("placeholder"))
					return false;
				}
				/*var userName = $("#txtUserName").val();
				if($.trim(userName).length == 0){
					layer.msg($("#txtUserName").prop("placeholder"))
					return false;
				}
				var userTel = $("#txtUserTel").val();
				if($.trim(userTel).length == 0){
					layer.msg($("#txtUserTel").prop("placeholder"))
					return false;
				}*/
				var shipDate = $("#txtShipDate").val();	
				if($.trim(shipDate).length == 0){
					layer.msg("请输入发货日期")
					return false;
				}
				refundExpress = {
						"shipNo":shipNo,
						"shipCompany":shipCompanyName,
						/*"userName":userName,
						"userMobile":userTel,*/
						"shipDate":shipDate
					};
			}
		}
		
		var orderId = init.orderId;
		var applyInfo = {
		     "orderId":orderId,
		     "remark":remark,
		     "orderDetailList":orderDetails,
		     "refundExpress":refundExpress,
		     "isSend":isSend
		};
		
		if(clickStatus){
			clickState = false;
			$.ajax({
				url:basePath+"/order/saveRefund.shtml",
				data:{"applyInfo":JSON.stringify(applyInfo)},
				type:"post",
				dataType:"JSON",
				success:ajaxSuccessCloseFun
			});	
		
		}
		
		
		
	});
    //显示物流信息填写列表
    $("#is_ship_true").click(function(){
    	$("#ship_div").show();
    });
    //隐藏物流信息填写列表
    $("#is_ship_false").click(function(){
    	$("#ship_div").hide();
    });
  //显示物流信息填写列表
    $("#is_send_true").click(function(){
    	$("#send_goods").show();
    });
    //隐藏物流信息填写列表
    $("#is_send_false").click(function(){
    	$("#send_goods").hide();
    });
});